package Xiancheng;

public class Storage
{
	private static int size;
	public synchronized void add() 
	{
		if(size>0) 
		{
			System.out.println("有菜了");
			try
			{
				this.wait();
			} catch (InterruptedException e)
			{
				e.printStackTrace();
			}
			
		}else 
		{
			size++;
			System.out.println("我放了一盘菜"+size);
			this.notifyAll();
		}
	}
	public synchronized void remove() 
	{
		if(size>0)
		{
			System.out.println("我取了一盘菜");
			size--;
			this.notifyAll();
		}else 
		{
			System.out.println("没有菜了");
			try
			{
				this.wait();
			} catch (InterruptedException e)
			{
				e.printStackTrace();
			}
		}
	}
}
